<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增用户')" />
<!-- 	<th:block th:include="include :: select2-css" /> -->
</head>
<style>
.layui-form-label{width:110px;}
.layui-input-block{margin-left:140px;}
.layui-form-radio{padding-right:0}
.layui-icon-more{position: absolute;right: 10px;top: 7px;cursor: pointer;}
</style>
<body>
    <div class="container" style="padding:0 15px;">
	    <fieldset class="layui-elem-field layui-field-title">
	    	<legend>用户信息</legend>
	  	</fieldset>
	    <form class="layui-form" id="form-user-add" lay-filter="form-user">
	    	<div class="layui-form-item">
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label"><font class="f_red">*</font>用户编号</label>
	      			<div class="layui-input-block">
		        		<input type="text" name="userId" id="userId" th:value="${sysUserInfo?.userId}" lay-verify="required" autocomplete="off" th:class="${sysUserInfo}?'layui-input canntEdit':'layui-input'" th:readonly="${sysUserInfo}? 'true' : 'false'" onblur="inputOnBlur(this)">
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label"><font class="f_red">*</font>用户名称</label>
	      			<div class="layui-input-block">
		        		<input type="text" name="userName" id="userName" th:value="${sysUserInfo?.userName}" lay-verify="required" autocomplete="off" class="layui-input" onblur="inputOnBlur(this)">
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">用户级别</label>
	      			<div class="layui-input-block">
		        		<select name="userLevel">
					        <option value="">请选择用户级别</option>
					        <option th:each="userLevelList:${userLevelMap}" th:value="${userLevelList.key}" th:text="${userLevelList.value}" th:selected="${userLevelList.key} eq ${sysUserInfo?.userLevel}"></option>
				      	</select>
		      		</div>
			    </div>
		  	</div>
		  	<div class="layui-form-item">
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">用户状态</label>
	      			<div class="layui-input-block">
		        		<input type="checkbox" th:checked="${sysUserInfo?.disabled == false or sysUserInfo?.disabled == null}" name="disabled" lay-skin="switch" lay-text="启用|禁用">
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">员工状态</label>
	      			<div class="layui-input-block">
		        		<input type="radio" name="userState" value="试用" title="试用" th:checked="${sysUserInfo?.userState == '试用' or sysUserInfo?.userState == null}">
      					<input type="radio" name="userState" value="在职" title="在职" th:checked="${sysUserInfo?.userState == '在职'}">
      					<input type="radio" name="userState" value="离职" title="离职" th:checked="${sysUserInfo?.userState == '离职'}">
		      		</div>
			    </div>
		  	</div>
<!-- 		  	<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">学历</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<select name="userSchooled"> -->
<!-- 					        <option value="">请选择学历</option> -->
<!-- 					        <option value="小学" th:selected="'小学' eq ${sysUserInfo?.userSchooled}">小学</option> -->
<!-- 					        <option value="中学" th:selected="'中学' eq ${sysUserInfo?.userSchooled}">中学</option> -->
<!-- 					        <option value="高中" th:selected="'高中' eq ${sysUserInfo?.userSchooled}">高中</option> -->
<!-- 					        <option value="中专" th:selected="'中专' eq ${sysUserInfo?.userSchooled}">中专</option> -->
<!-- 					        <option value="大专" th:selected="'大专' eq ${sysUserInfo?.userSchooled}">大专</option> -->
<!-- 					        <option value="本科" th:selected="'本科' eq ${sysUserInfo?.userSchooled}">本科</option> -->
<!-- 					        <option value="研究生" th:selected="'研究生' eq ${sysUserInfo?.userSchooled}">研究生</option> -->
<!-- 					        <option value="硕士" th:selected="'硕士' eq ${sysUserInfo?.userSchooled}">硕士</option> -->
<!-- 					        <option value="博士" th:selected="'博士' eq ${sysUserInfo?.userSchooled}">博士</option> -->
<!-- 					        <option value="博士后" th:selected="'博士后' eq ${sysUserInfo?.userSchooled}">博士后</option> -->
<!-- 				      	</select> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">身份证号</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userIdCard" th:value="${sysUserInfo?.userIdCard}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">生日</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userBirthday" th:value="${#dates.format(sysUserInfo?.userBirthday,'yyyy-MM-dd')}" id="userBirthday" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
		  	<div class="layui-form-item">
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">性别</label>
	      			<div class="layui-input-block">
		        		<input type="radio" name="userSex" value="男" title="男" th:checked="'男' eq ${sysUserInfo?.userSex}">
      					<input type="radio" name="userSex" value="女" title="女" th:checked="'女' eq ${sysUserInfo?.userSex}">
      					<input type="radio" name="userSex" value="同步档案" title="同步档案" th:checked="'同步档案' eq ${sysUserInfo?.userSex}">
		      		</div>
			    </div>
		  	</div>
		  	<div class="layui-form-item">
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">省份</label>
	      			<div class="layui-input-block">
		        		<select name="userProvince" id="userProvince" lay-filter="userProvince" th:with="type=${@baseinfosimple.getBaseInfoSimpleData('area2')}">
		        		<option value="">请选择</option>
						<option th:each="dict : ${type}" th:text="${dict.vname}" th:data-guid="${dict.guid}" th:value="${dict.vid}" th:selected="${dict.vid} eq ${sysUserInfo?.userProvince}"></option>
				      	</select>
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">城市</label>
	      			<div class="layui-input-block">
		        		<select name="userCity" id="userCity" lay-filter="userCity">
				      	</select>
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">地址</label>
	      			<div class="layui-input-block">
		        		<input type="text" name="userAddress" th:value="${sysUserInfo?.userAddress}" autocomplete="off" class="layui-input">
		      		</div>
			    </div>
		  	</div>
<!-- 		  	<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">联系电话</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userPhone1" th:value="${sysUserInfo?.userPhone1}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">备用电话</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userPhone2" th:value="${sysUserInfo?.userPhone2}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">邮箱</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userEmail" th:value="${sysUserInfo?.userEmail}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
<!-- 		  	<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">微信</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userWeChat" th:value="${sysUserInfo?.userWeChat}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">QQ</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userQQ" th:value="${sysUserInfo?.userQQ}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
<!-- 			<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">档案照片</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userPhoto" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">用户头像</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="userPicture" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
<!-- 			<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人关系1</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relations1" th:value="${sysUserInfo?.relations1}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人1</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relationName1" th:value="${sysUserInfo?.relationName1}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人电话1</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relationPhone1" th:value="${sysUserInfo?.relationPhone1}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
<!-- 			<div class="layui-form-item"> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人关系2</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relations2" th:value="${sysUserInfo?.relations2}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人2</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relationName2" th:value="${sysUserInfo?.relationName2}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 			    <div class="layui-col-sm4"> -->
<!-- 			      	<label class="layui-form-label">紧急联系人电话2</label> -->
<!-- 	      			<div class="layui-input-block"> -->
<!-- 		        		<input type="text" name="relationPhone2" th:value="${sysUserInfo?.relationPhone2}" autocomplete="off" class="layui-input"> -->
<!-- 		      		</div> -->
<!-- 			    </div> -->
<!-- 		  	</div> -->
			<div class="layui-form-item">
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label"><font class="f_red">*</font>岗位</label>
	      			<div class="layui-input-block">
		        		<input type="text" id="positionName" autocomplete="off" class="layui-input" lay-verify="required"/>
		        		<input type="hidden" name="PositionGuid" id="PositionGuid">
	      				<i class="layui-icon layui-icon-more" onclick="modalSelect('positionName')"></i>
		      		</div>
			    </div>
			    <div class="layui-col-sm4">
			      	<label class="layui-form-label">所属上级</label>
	      			<div class="layui-input-block">
		        		<input type="text" name="userLeader" id="userLeader" th:value="${sysUserInfo?.userLeader}" autocomplete="off" class="layui-input" />
	      				<i class="layui-icon layui-icon-more" onclick="modalSelect('userLeader')"></i>
		      		</div>
			    </div>
			    <div class="layui-col-sm4" th:if="${buttonState['relatebtn']} neq 'hidden'" >
			      	<label class="layui-form-label">关联档案</label>
	      			<div class="layui-input-block">
		        		<input type="text" id="daXX" autocomplete="off" class="layui-input" />
		        		<input type="hidden" name="DANid" id="DANid"/>
	      				<i class="layui-icon layui-icon-more" onclick="modalSelect('daXX')"></i>
		      		</div>
			    </div>
		  	</div>
	        <div class="layui-form-item" style="text-align: center;">
	            <div class="layui-input-block" style="margin:0;">
	                <button class="layui-btn" lay-submit lay-filter="btn-add">保存</button>
	                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	            </div>
	        </div>
	    </form>
	</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
/*<![CDATA[*/
var pageType = "[[${pageType}]]";
var userProvince = "[[${sysUserInfo?.userProvince}]]";
var userCity = "[[${sysUserInfo?.userCity}]]";
/*]]>*/
var $,layer,form,table,laydate,postStr = [];
layui.use(['laydate', 'table','form','layer','jquery'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate;
	laydate.render({elem:'#userBirthday',type:'date',format: "yyyy-MM-dd"});
	$(function(){
		var cProvince = $("[name=userProvince]").find("option:selected").attr("data-guid");
		if(cProvince){
			$.ajax({
				url: '/base/baseinfo/list?pguid='+cProvince,
		        type: 'get',
		        dataType: 'json',
				success: function(result) {
					$('#userCity').append(new Option('请选择城市',''));
					$.each(result.data,function(i,v){
						if(v.vname == userCity){
							$('#userCity').append('<option value="'+v.vid+'" data-guid="'+v.guid+'" selected>'+v.vname+'</option>')
						}else{
							$('#userCity').append('<option value="'+v.vid+'" data-guid="'+v.guid+'">'+v.vname+'</option>')
						}
		        	});
					form.render();
				}
			});
		}
	})
	//联动获取城市列表
	form.on('select(userProvince)', function(data){
    	var pguid = data.elem[data.elem.selectedIndex].dataset.guid;
    	getCity(pguid);
	})
	function getCity(pguid,cityname){
		$.ajax({
			url: '/base/baseinfo/list?pguid='+pguid,
	        type: 'get',
	        dataType: 'json',
	        success: function(result) {
	        	var areaList = '<option value="">请选择城市</option>';
	        	$.each(result.data,function(k,v){
	        		if(cityname == v.vname){
	        			areaList += '<option value="'+v.vname+'" data-guid="'+v.pguid+'" selected>'+v.vname+'</option>';
	        		}else{
	        			areaList += '<option value="'+v.vname+'" data-guid="'+v.pguid+'">'+v.vname+'</option>';
	        		}
	        	});
	        	$("#userCity").empty();
	        	$("#userCity").append(areaList);
	        	form.render('select');
	        }
		})
	}
    form.on('submit(btn-add)', function(data){
    	data.field.disabled = data.field.disabled === "on" ? "0":"1";
		postStr.push(data.field);
           //TODO:提供一个检测表单数据检测性通用方法
           if(true){
           	if(pageType == 'edit'){
           		var url = "/system/user/editpost";
           		var data = {'userInfoItems':JSON.stringify(postStr),'upType':'upuser'};
           	}else{
           		var url = "/system/user/addpost";
           		var data = {'userInfoItems':JSON.stringify(postStr)};
           	}
           	$.operate.post(url,data,function(result){
           		setTimeout(function(){
                       window.location.reload();
                   }, 1000);
           	});
           }
           return false;
       });
})
function modalSelect(forField){
	switch(forField){
		case 'userLeader':
			var title = "选择上级", url = "/system/user/userselect?pagetype=radio", mWidth = "600", mheight = "470";
			break;
		case 'daXX':
			var title = "选择档案", url = "/hr/personneldaxx/select";
			break;
		case 'positionName':
			var title = "选择岗位", url = "/system/role/select", mWidth = "500", mheight = "460";
			break;
	}
 	$.modal.open(title,url,mWidth,mheight,function(index){
    	var res = window["layui-layer-iframe" + index].callbackdata();
    	if(!!res){
	    	switch(forField){
	        	case 'userLeader':
	        		$("#userLeader").val(res.userId);
	        		break;
	        	case 'daXX':
	        		$("#daXX").val('"'+res.userName+'"' + " 的档案");
	        		$("#DANid").val(res.nid);
	        		break;
	        	case 'positionName':
	        		$("#positionName").val(res.roleName);
	        		$("#PositionGuid").val(res.guid);
	        		break;
	    	}
       	 layer.closeAll();
         }else{
             layer.msg("请选择人员！");
         }
	})
}
</script>
</body>
</html>
